import React from 'react';
import { getOperateDetails } from '@/pages/Task/services/taskActions';
import InfoModal from '../../../components/InfoModal';
import { Icon } from 'antd';

export const showReckonInfoModal = async (id, operateRecordId) => {
    const employeeString = employeeList => {
        const employee = (employeeList && employeeList.length > 0 && employeeList.map(item => item.employeeName)) || [];
        return employee.join('；');
    };
    // 详情附件
    const renderFiles = files => {
        const upload = files.map(item => (
            <div key={item.id}>
                {item.originName}
                <a rel="noopener noreferrer" target="_blank" style={{ marginLeft: 8 }} href={item.url} download>
                    <Icon type="download" />
                </a>
            </div>
        ));
        return files.length > 0 ? upload : '无';
    };
    const columns = [
        {
            title: '选择重估人员',
            require: true,
            dataIndex: 'employeeList',
            render: (_, record) => employeeString(record.employeeList)
        },
        {
            title: '原因',
            dataIndex: 'operateReason',
            require: true
        },
        {
            title: '附件',
            dataIndex: 'taskReEstimationFile',
            render: (_, record) => (record.taskReEstimationFile ? renderFiles(record.taskReEstimationFile) : '')
        }
    ];
    // TODO 后续改为接口代码
    const { data } = await getOperateDetails(id, operateRecordId);
    return InfoModal.showCommonModal({ columns, dataSource: data, title: '重估申请详情' });
};
